Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript to open link

Status
Not open for further replies.

SaMaster

Programmer
Joined
May 11, 2006
Messages
8
Location
BA
Can somebody tell me can I open a document(pdf link in a site) with javascript and without clicking on the link?
 
I didnt test your code but I am not sure if you did understand?

I have a external link to a site for exmpl. named test.aspx.
<a href="test.aspx">Test site</a>

On this site(test.aspx) is an pdf link for exmpl. document.pdf

I want to do this think:

Klick on Test site opens the site and automatic open the document.pdf

So now tell me is this code right which you gave me?
 
If you want to open the PDF directly, then simply link to it directly!

Code:
<a href="[URL unfurl="true"]http://the.site.address.com/thepdffilename.pdf">[/URL]

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
No I cant do this because of security reasons.I need 2 sites.On the first a link that informs a user that there is a pdf document.On click this link it should open new site and execute the link on the site without clicking(auto)-quasi redirect to the link

Can I do this?
 
If it's simply a matter of informing the user, you could use the above method in combination with a "window.confirm" call to prompt them to agree or not agree to opening it.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi again,

its not "simply" a information that a pdf exist- its a link to the site where the link is placed on.
And I want open this document without clicking on its link.
 
Again

I must see if a User is logged in.If he is, he can open the document.When not ho should be redirected to login page.
How to do this?
How can I prevent somebody from opening apdf document if he isn not logged in?

I hope you can help me:)
 
Do you have access to the site where the pdf is?

Cheers,
Dian
 
Then you can do what people suggested here in the onLoad method of the second page.

Cheers,
Dian
 
what is the synthax of dis insturction?
no matter which lanugage
 
Your exact requirements have never been clear, becase you change them, or add things, every time you post.

You first asked how to open a PDF without clicking. You were shown this.

Then you came back with more requirements, saying the PDF was actually on a different site, which you wanted to open, and then open the PDF. You did not specify you wanted the PDF opened as well as the new site, so I assumed you simply wanted to replace it, and thus gave you the short code to simply open a PDF on a remote site (albeit with clicking).

Then you added another requirement - informing the user that they will be opening a PDF. I told you how to do this (with a window.confirm, giving the user the chance to opt out).

Then you said you DIDN'T want to inform the user, which contradicted your previous statement, simply saying you want to open a document without clicking (which gbaughma showed you how to do in his first post right at the top of this thread).

Now you say you wat to see if a user is logged in or not - which is yet another requirement.

So - to open a PDF (or ANY file) without clicking, use the code that was posted right at the top of this thread. You can put in in an onload event like so:

Code:
<body onload="window.open('somePDF.pdf', '', '');">

If that is not what you want, then please, for the sake of brevity, can you just list all of your requirements in once place, without adding more every time someone posts.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Incidentally, opening files like this will fall foul of most popup blockers, as most of them only allow user-instigated windows to open (i.e. they will only work when a user actually clicks on a link).

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Billy,

The above code did not help.But I cleared the problem as follows:

1) made a new web site which can be viewed by logged users
2)Redirect the site to the link

Now its ok but thank you for you help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top