Jump to content
  • Advertisement
Sign in to follow this  
ElyasMachera

[web] How to call a link without redirecting a page

This topic is 2556 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,
I have a shortened link, for example like http://bit.ly but I need to find out what url it really is..
I was told I could use javascript to make an asynchronous call to the page and get the header information or something, which will give me the status code if it is redirecting and the actual link..I am newbie, and I don't know wtf that is lmao..
Can someone tell me if there is a way I can get this done with javascript thanks.

Share this post


Link to post
Share on other sites
Advertisement

I was told I could use javascript to make an asynchronous call to the page and get the header information or something, which will give me the status code if it is redirecting and the actual link
You can only make asynchronous requests to the host of the page you're currently viewing, so this won't work.

Is it an option for you to do this server-side, instead of on the client?

Share this post


Link to post
Share on other sites
If you want the fast and easy dirty way to do it use PHP and Bit.ly API:

$url = 'url'; // you can use javascript to set this or php to dynamically set it
include('bitly.php'); //api php
$bitly = new bitly('username', 'apikey'); //your username and apikey for the bitly serviceecho
$bitly->expand($url);


-Mayple

Share this post


Link to post
Share on other sites

If you want the fast and easy dirty way to do it use PHP and Bit.ly API:

$url = 'url'; // you can use javascript to set this or php to dynamically set it
include('bitly.php'); //api php
$bitly = new bitly('username', 'apikey'); //your username and apikey for the bitly serviceecho
$bitly->expand($url);


-Mayple

Your method would have been very useful if I could assign a javascript value to a php variable without using a get or post..or is there a way to do that? Because so far I have no idea how to do that


Share this post


Link to post
Share on other sites

[quote name='Mayple' timestamp='1310295135' post='4833290']
If you want the fast and easy dirty way to do it use PHP and Bit.ly API:

$url = 'url'; // you can use javascript to set this or php to dynamically set it
include('bitly.php'); //api php
$bitly = new bitly('username', 'apikey'); //your username and apikey for the bitly serviceecho
$bitly->expand($url);


-Mayple

Your method would have been very useful if I could assign a javascript value to a php variable without using a get or post..or is there a way to do that? Because so far I have no idea how to do that

[/quote]

you could use ajax and load the php script the background which should make the use of get or post pretty much irrelevant for the end user (Which is all that matters)

Share this post


Link to post
Share on other sites
check out CURL which can call a remote url from your server (php).
create a local php that calls the remote url and returns the result.
call the local php from ajax.

Share this post


Link to post
Share on other sites
Those are really good ideas, unfortunately It has to be strictly javascript and php
what about the XMLHttpRequest object? can it accomplish what i want without reloading the page?

Share this post


Link to post
Share on other sites

[quote name='Elyas_321' timestamp='1310332080' post='4833459']
[quote name='Mayple' timestamp='1310295135' post='4833290']
If you want the fast and easy dirty way to do it use PHP and Bit.ly API:

$url = 'url'; // you can use javascript to set this or php to dynamically set it
include('bitly.php'); //api php
$bitly = new bitly('username', 'apikey'); //your username and apikey for the bitly serviceecho
$bitly->expand($url);


-Mayple

Your method would have been very useful if I could assign a javascript value to a php variable without using a get or post..or is there a way to do that? Because so far I have no idea how to do that

[/quote]

you could use ajax and load the php script the background which should make the use of get or post pretty much irrelevant for the end user (Which is all that matters)
[/quote]


<?php
if (1==1)
{
?>
<script language="JavaScript">
bitlyURL = INPUT METHOD; // use this to assign your bitly url, add either a form, a post, a get, anything you want. a document write maybe?
urlString = "bitly.php?var=" +bitlyURL;
window.location = urlString;

</script>
<?php
$url = $_GET["bitlyURL"];
$bitly = new bitly('username', 'apikey'); //your username and apikey for the bitly serviceecho
$bitly->expand($url);
}
?>


[color="#000000"]Above is very rough, but should put you in the right direction.
-Mayple

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!