Welcome to WebmasterWorld Guest from 50.16.24.12

Forum Moderators: open

JS - Open in new window

Simplest way to do this?

   
12:02 pm on Oct 3, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hi all,

How do I make a link like this open in a new window?

<a href="javascript:self.location='page.html';">some page</a>

thanks

Nick

12:21 pm on Oct 3, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



er....

and make the window that remains still the same as where they left it!

Heres what I managed to work out myself:

<a href="javascript:window.open('page.html');">page</a>

but the window that's left behind just has a blank page with:

object[object]

or something on it?

Nick

2:54 pm on Oct 3, 2002 (gmt 0)

10+ Year Member



Well, I tried what you said, and indeed, it does do just that.

Did you notice that your window that says [object] also has javascript:window.open("blah.html") in it?

So, what happened was, when you clicked your link, the webpage actually *became* just "javascript:window.open("blah.html");" (try mozilla to see this. I believe IE does something different).

And, that line still got executed, and the new window, blah.html, opened as well.
Right? Hehe Im not totally clear on all of this.

So, instead, I made a one-line fuction called doit() with just
window.open("blah.html"); in it
and the href looks like:

<a href = "javascript:doit()">Click y0</a>

And it worked great!

2:55 pm on Oct 3, 2002 (gmt 0)

10+ Year Member



Did you notice that your window that says [object] also has javascript:window.open("blah.html") in it?

I mean, the navigation bar of the initial window has javascript:window.open("blah.html") in it :).

k just clarifying

3:07 pm on Oct 3, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Right thanks!

Can I see the function?
And would I be able to call it with different urls each time?

Cheers

Nick

3:14 pm on Oct 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<a href="http://www.mysite.com/other.html" onclick="window.open(this.href);return false;">another page (new window)</a>

Spider-friendly, 'cuz the href attribute is there and gets used. No change to the current window because if the onclick handler returns false, the browser isn't supposed to follow the link.

<added>Also degrades well, since if js is disabled, the browser still has a link to follow, and will.</added>

[edited by: dingman at 3:24 pm (utc) on Oct. 3, 2002]

3:23 pm on Oct 3, 2002 (gmt 0)

10+ Year Member



Can I see the function?

function doit(){
window.open('view.php');
}

Now, here is another way: (I am not very sure about the whole "spider-friendly" thing, because I dont even know what that is ;))

<a href = "javascript:windowHandle = window.open('view.php','windowname','width=500,height=500,location=yes'); windowHandle.focus();">Click y0</a>

the windowHandle.focus is quite necessary...

3:24 pm on Oct 3, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Great, thanks dingman ;)

How do I make it spider un-friendly?

Nick

3:29 pm on Oct 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nick, do you mean "I want spiders to not follow this link, how do I do that?" or "Dingman, you fool, you're overlooking something that makes a javascript: pseudo-url perfectly OK for spiders?"

If the former, my guess would be that instead of
<a href="http://www.mysite.com/other.html" onclick="window.open(this.href);return false;">another page (new window)</a>

you could do
<a href="doesn't matter as long as onclick returns false" onclick="window.open('other.html');return false;">another page (new window)</a>

If the latter, enlighten me :)

3:37 pm on Oct 3, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



hehe, no you're not a fool!

I just don't want the spiders to follow the link to the popup. It's for affiliate links and I don't want them draining PR.

Will what you said in your last post be okay for that criteria?

Thank,

Nick

3:49 pm on Oct 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As far as I know, yes. I'd probably make the "href" point to an internal page with an explanation for the users who have javascript turned off, to keep from completely confusing them.

I'm a lot less experienced than you are, and search engine behavior is not something I'm used to thinking about, let alone knowledgable about. September 10th, I didn't even know what "page rank" was. Might want to ask whether googlebot or any of the other search engine spiders have js interpreters. If so, I don't think anything we've looked at will hide from them.

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month