Welcome to WebmasterWorld Guest from 3.227.208.153

Forum Moderators: open

Message Too Old, No Replies

JS - Open in new window

Simplest way to do this?

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

Senior Member

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

joined:Feb 4, 2002
posts:5044
votes: 0


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)

Senior Member

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

joined:Feb 4, 2002
posts:5044
votes: 0


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)

Preferred Member

10+ Year Member

joined:Sept 24, 2002
posts:364
votes: 0


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)

Preferred Member

10+ Year Member

joined:Sept 24, 2002
posts:364
votes: 0


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)

Senior Member

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

joined:Feb 4, 2002
posts:5044
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 12, 2002
posts:885
votes: 0


<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)

Preferred Member

10+ Year Member

joined:Sept 24, 2002
posts:364
votes: 0


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)

Senior Member

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

joined:Feb 4, 2002
posts:5044
votes: 0


Great, thanks dingman ;)

How do I make it spider un-friendly?

Nick

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 12, 2002
posts:885
votes: 0


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)

Senior Member

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

joined:Feb 4, 2002
posts:5044
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 12, 2002
posts:885
votes: 0


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.