/    Sign up×
Community /Pin to ProfileBookmark

URL Preview Assistance

Greetings,

I’m new to javascript but I’ve written the following code that lets users preview a typed in URL in a new browser window. It works, but it needs some error checking.

Can anyone help me out with the error checking part or does anyone know where I can find a script that has error checking in it?

Here’s the script I wrote:

<SCRIPT LANGUAGE=”JavaScript”>
<!– // Start Preview Button
function showPage() {
var opts = ‘toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes’;
var URL = document.form1.Address.value;
var sourcewin = window.open(URL,’Preview’,opts)
}
// End Preview Button –>
</SCRIPT>

<form name=”form1″>
<input name=”Address” type=”text” id=”Address” size=”50″ maxlength=”255″>
<input type=”button” value=”Preview” onClick=”showPage()”>
</form>

Thank you so much for any help you can offer!

Warm regards,
– utdream

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@NevermoreFeb 09.2003 — looks like your only problem is that the user has to enter http:// at the start of the txtbox.

If you want a script that does that for them, ill post one in a sec.
Copy linkTweet thisAlerts:
@NevermoreFeb 09.2003 — Dont worry, if they entered http:// it wont be duplicated. The script checks. I also made the button a submit button, so that you can 'press' it with enter, and made the text box originally read http://. Here it is. If it isnt what u wanted, PM me.

<SCRIPT LANGUAGE="JavaScript">

<!-- // Start Preview Button

function showPage() {

var URL = document.form1.Address.value;

var check = URL.substring(0, 7);

if (check != "http://") {

URL = "http://" + URL;

}

var opts = 'toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes';

var sourcewin = window.open(URL,'Preview',opts)

}

// End Preview Button -->

</SCRIPT>

<form name="form1" onSubmit="showPage()">

<input name="Address" type="text" id="Address" size="50" maxlength="255" value="http://">

<input type="submit" value="Preview" >

</form>
Copy linkTweet thisAlerts:
@NevermoreFeb 09.2003 — oh, and you need to make sure that the opts line IS just one line (i know its just the forum doing that).
Copy linkTweet thisAlerts:
@utdreamauthorFeb 09.2003 — Awesome. Works like a charm. Now that I see what you've done I kinda feel silly for not thinking of it myself! ?

There's also an error that happens when the user doesn't type in any URL at all, but if they're trying to preview a blank URL they deserve to get an error huh? :rolleyes:

Thank you so much for your help! You rule man!

Warm regards,

- utdream
×

Success!

Help @utdream spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...