Posts filed under 'Javascript'

target=”_blank” With XHTML 1.1

I received a question this morning from someone asking:

In XHTML 1.1 we cannot use attribute ‘target=blank’, so what is the solution?

The solution is to use regular links, but to make them open into a new window using JavaScript. To do this, we can add something to the links to flag them as being special, perhaps a class called new-window:

<a href="page.html" class="new-window">Page</a>

Then, use JavaScript to find all the links that have this class name and tell them to open in a new window:

window.onload = function() {
    var links = document.getElementsByTagName('a');
    for (var i=0;i < links.length;i++) {
        if (links[i].className == 'new-window') {
            links[i].onclick = function() {
                window.open(this.href);
                return false;
            };
        }
    }
};

or using jQuery:

$(function(){
    $('a.new-window').click(function(){
        window.open(this.href);
        return false;
    });
});

If you have any other questions like this, feel free to ask me and I’ll be happy to answer them here.

Add comment April 16, 2009

Add Favorite Link

<script type=”Text/Javascript”><!–
var url = “http://www.mysite.com”;
var title = “My Website”;
function addToFavorites() {
if (window.sidebar) {
window.sidebar.addPanel(title, url,”");
} else if (window.external) {
window.external.AddFavorite(url,title)
} else {
alert(“Sorry! Your browser doesn’t support this function.”);
}
}
if (!window.sidebar && !window.external) {
document.getElementById(‘bookmarkPage’).style.display = ‘none’;
}
// –></script>

Add comment February 26, 2009

Javascript: Print preview window

I would like to create a print preview window that will display only the main content of the page that a person would really want to print. It can work fine on IE and Firefox..You can test other browser. :D

(more…)

Add comment July 25, 2008

Clicking a button in Javascript doesn’t always work in Firefox

Clicking a button in Javascript always work in IE but not in Firefox.

I’ve run into a javascript problem a few times which -for a refreshing change – shows itself as Firefox not behaving as you might expect (… well Firefox together with ASP.NET at any rate).
(more…)

Add comment July 23, 2008

XPath

XPath uses path expressions to select nodes or node-sets in an XML document.
The node is selected by following a path or steps.
(more…)

Add comment December 28, 2007

Previous Posts


Categories

Category Cloud

.Net Business HTML & CSS & DOM Javascript PHP Tool

Tags

.Net ADO.NET ajax Business Javascript Oracle ADO.NET Subversion .Net Subversion SVN Source VB.Net

Recent Posts

Archives

Blogroll

Recent Comments

Asaduzzaman Arif on Encrypt/Decrypt string VB…
Pranav on Encrypt/Decrypt string VB…
ntcnet on Encrypt/Decrypt string VB…
Elena on Encrypt/Decrypt string VB…
Elena on Encrypt/Decrypt string VB…

Twitter