Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7646313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:10:32+00:00 2026-05-31T10:10:32+00:00

I am trying to understand how to include JavaScript externally so the code prints

  • 0

I am trying to understand how to include JavaScript externally so the code prints to the page.

When I insert the JavaScript directly into the page code, it prints “hello”

<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">document.write("hello");</script>
</body>
</html>

However, when I put that same code into external file say “javascript.js” and include it (src) in the html it does not print “hello”?

<html>
<head>
<title></title>
<script type="text/javascript" src="http://thewebsite.com/javascript.js"></script>
</head>
<body>
</body>
</html> 

I am trying to understand how to get that external JavaScript file to run and print “hello”.
How does XSS work then if a hacker was to include the following tag inside say a textarea to call his malicious script from malicious server?

<script type="text/javascript" src="http://thewebsite.com/javascript.js"></script>

Heres whats in the “javascript.js” file:

<script type="text/javascript">
document.write("hello");
</script>

The file is on the same domain so Same Origin Policy should not apply here and as mentioned if I directly insert code it does work but not when I try to include as separate file.

I thought including JavaScript as external file, should print the contents of the external file (i.e. “hello” in this case) as if it was directly inserted in html page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:10:33+00:00Added an answer on May 31, 2026 at 10:10 am

    I guess there is a policy enforced by browsers called Same Origin Policy which makes sure that JS from different domains does not access each others data when loaded in a single page. Lets say that you have a Google Ad and it has some Javascript in it. It wouldn’t be advisable if the script in Google Ads be able to access the data in your site (Vice-Versa but ofcourse you always have Google Ads or the Like button as iFrame and hence anyways they are most neatly seperated.)

    If you could load the js file as a src to image file then I suppose you can achieve what you intend to.(If I am not wrong.)

    Edit: The javascript file cannot be given as input to the src of img tag. You can only use it as javascript: scheme.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to understand something with pointers, so I wrote this code: #include
Trying to understand Ruby a bit better, I ran into this code surfing the
After trying to understand why client code is not rendered in a page (injected
I am trying to understand this code: #include<stdio.h> int main() { extern int a;
I'm trying to understand this bit of code: in display.php: <html> ... <body> <table>
I am trying to understand the following code: #include<stdio.h> #include<stdlib.h> #include<sys/io.h> #define baseport 0x378
I'm trying to include the Sparkle framework in my application. I don't really understand
Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults
I am trying to get two jQuery slides to work in a HTML page.
I was trying to understand forks, and tried following in C: #include<stdio.h> #include <unistd.h>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.