Domanda

I'm attempting to use javascript to modify the url on page. This URL is then being passed into the bit.ly bookmarklet to be shortened. My script will append a parameter to the URL and insert it into the URL field of the bit.ly bookmarklet. If this works i would combine the code of the bit.ly bookmarklet with the script to automatically perform its task.

The process is as follows:

Run bit.ly bookmarklet, run my script to append parameter, use bit.ly bookmarklet

Source of bit.ly bookmarklet

<div id="mainUnAuthShortenContainer" class="inputBoxContainer">
<input tabindex="1" id="shortenUnAuthContainer" name="url" value="https://www.google.com/" type="text">
</div>

My script

var elem = document.getElementById("shortenUnAuthContainer");
elem.value = window.location + "?Parameter";

My script works in JSFiddle but not in real application. It does nothing when applied to the actual bit.ly bookmarklet. Any help is appreciated.

The bit.ly bookmarklet for reference. Thanks!

È stato utile?

Soluzione

It's impossible.

Reason: accessing element in iframe(the URL inner iframe is different with parent window) is deny by browser.

More: You are trying to access a element which is not yet create, the time JS/iframe/element are still on loading. if you solve this problem, then you will still met the limitation above..

*I checked bitly API documentation, there is a solution may works if you have a PHP server - deploy you own bitly service: https://code.google.com/p/bitly/

FYI, bitly code lib: http://dev.bitly.com/code_libraries.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top