javascript file directory redirect? - redirect

I have some javascript that changes the title image based on whatever the host is. My problem is that the redirect path I have "../images/file.jpg" does not work for all the pages that I have. Some of my main pages are in the main folder directory, the others are in a separate folder within the main directory folder called page. All the images used(not located) in page treat page as the main dir.
Does anyone know a way around this, without me having to move the images?
this is my script:
if(host == 'mysite.com') {
document.getElementById("geekhospitalextended").src='../images
/logo/IPD/title/IPD extended.png';
document.getElementById("urlTitle").src='../images/logo/IPD/title/
IPD extended.png';
}
I have thought about adding some code like:
if(pathname == 'mysite.com/directory1/directory2/images') {
document.getElementById("geekhospitalextended").src='../../../images
/logo/IPD/title/IPD extended.png';
document.getElementById("urlTitle").src='../../../images/logo/IPD/title/
IPD extended.png';
}
What could I do if I wanted to set the src path given that certian keywords are included in the path name
Any ideas?

Related

Magento 2 - Category Image URL showing two paths

Buit of a strange one, but hopefully it's easy to resolve.
I have uploaded some product Category images to certain category pages in the Admin client but when I view them on the web they don't load. The reason appears to be that it is trying to load two paths in the src attribute, which are slightly different.
Any ideas what I need to do to resolve this... :-)
src="https://www.myurl.com/pub/media/catalog/category//pub/media/catalog/tmp/category/25mm.jpg"
As you can see there are two paths in the URL, one has "tmp" (in bold) and if I modify the SRC this one loads. It appears that it is prepending the URL?
Any ideas would be appreciated.
src="/pub/media/catalog/tmp/category/25mm.jpg" <- This one loads the image?
Since Magento 2.3.4 this problem occurs.
/vendor/magento/module-catalog/Model/Category/Attribute/Backend/Image.php
public function beforeSave($object)
In This method below code is creating issue
$value[0]['url'] = '/' . $baseMediaDir . '/' . $newImgRelativePath;
$value[0]['name'] = $value[0]['url'];
Update it with
$value[0]['url'] = $baseMediaDir . $newImgRelativePath;
$value[0]['name'] = $value[0]['name'];
This will fix issue
Do Not forget to override this file from your module to avoid direct core file changes
Github issue: https://github.com/magento/magento2/issues/28100
Which version of magento 2 do you use?
I've had a similar problem with magento 2.3.4
When you save a category for which you just added an image. The model that handles the category images won't move your image from the tmp folder to the pub/media/catalog/category (which should be the path to the image).
So you have to override to Image.php model from the catgeory to move the file from tmp after is saved.
Hope this will help you.

Relative Paths in VS Code

I work with a multi-root workspace in VS Code. Here's my folder structure:
project-one
-node_modules
-public
--css
---styles.css
--img
---global
-----logo.svg
--js
---main.js
--index.html
project-two
project-three
When I reference files in my index.html file, VS Code always wants me to write it like this (in index.html):
src="img/global/logo.svg"
That doesn't really make sense to me. Logically, I would write the relative path to the logo with a leading / before img as the img folder is at the same level as index.html. However, that doesn't work.
Can anybody explain me why? And will the path declarations work correctly like this when I upload these files to the server (the content of the public folder will then be at the root)?
Thanks.

Difficulty using BufferedImage in Eclipse

I have stored an image in a Resource folder 'Images':
src
-com.program
-Images
In the program I use
BufferedImage image =ImageIO.read(getClass().getResourceAsStream("/myImage.png"));
to import the image.
This works fine. However, if i change the name of the image at the source(say to myImage1.png)
and try to execute
BufferedImage image =ImageIO.read(getClass().getResourceAsStream("/myImage1.png"));
I get Input==Null.
I've been try to get this to work for a while and tried various suggestions on other threads.
Any ideas?
Thanks!
The problem was most likely:
The image was in your src folder inside your project, but when the program runs, it runs from another folder containing your compiled classes. This folder did not contain the png, so you get the input == null exception (getClass().getResourceAsStream(...) returns null when resources cannot be resolved).
To make it work, you need to mark the images folder a resource folder (using Eclipse, Maven or favorite build tool), and make sure that the contents of that folder is on your class path when the program is run.

How to resolve Unable to find file.cpp in path(s) in Marmalade?

I'm just trying to begin develop a game in Marmalade (6.3). But when I have made my new sources (.cpp, and .h) and added them to the mkb, and then trying to run my program, then I got an error which says that Unable to find file.cpp in path(s). It's for all of my files except the files (game.h, game.cpp, main.cpp) which were made by Marmalade when I have chosen the new 2D game project. Should I add my .cpp and .h files to anywhere else?
Thanks
It is difficult to give a categorical answer without more info. However my guess is that you've copied and pasted from an example and not understood about the syntax of the files section. Basically:
files
{
(foo)
humbug.cpp
)
The "(foo)" might look very innocent, but it actually says that humbug.cpp is actually in directory foo - relative to the mkb file. It is common practice to actually use "(source)" and put all the source files in a directory of that name - making the source layout a bit neater.
Naturally if you have (source) and don't put the files actually in directory source, they won't be found. My guess is that is what you are seeing.
Just to clarify previous answer, The format of files directive is like this -
files
{
(<Path relative to MKB>,<Alternate Path>)
["Name of the parent Group in VS/XCode project","Name of the subparent group"]
fileName.cpp
fileName.h
}
for example I have two files SoundManager.h and SoundManager.cpp in System folder of Source, while MainMenu.h and MainMenu.cpp in Source/UI. Now the files directive would be -
files
{
(Source/System)
["Source","System"] #This part is not required, it's just to arrange your files in IDE project
SoundManager.h
SoundManager.cpp
(Source/UI)
("Source","UI")
MainMenu.h
ManinMenu.cpp
}

how to give the default path in gwt

i m creating a project in gwt (point) is project name ...
i want to store a image in point/war/images folder, whaich i gave the full path like C:\Documents and Settings\computer\workspace\m\war\images\ tthe the iamge will stored in images folder but i want to give the default path
i give "../war/images/" as default path, but this give me error (he system cannot find the path specified )
can any body help to give the default path
Usually you put images in the war/images directory, and you access them like
Image img = new Image("images/my_image.jpg")
You may also read this thread, and this question.